$(function(){
	var page = 1;
	loadPage(page);
	function loadPage(_page){
		$.ajax({
			url : ctx + "/web/jnyz/videoGrid",
			type : "post",
			data : {
				page : _page,
				rows : 10
			},
			success : function(data){
				page = _page;
				$("#news_data").html("");
				$("#totalPage").val(data.totalPage);
				$(".totalPageSpan").html(data.totalPage);
				var rows = data.rows;
				for(var i = 0; i < rows.length; i++){
					var publishDate = rows[i].publishDate;
					var pDate1 = publishDate.substring(0,7);
					var pDate2 = publishDate.substring(8);
					var id = rows[i].id;
					var title = rows[i].title;
					var brief = rows[i].brief;
					var shtml = $('<div class="xwconny">'+
									'<div class="dateny">'+
										'<P>'+
										pDate2+'<br>'+pDate1+
										'</P>'+
									'</div>'+
									'<div class="connrny">'+
										'<h1>'+
											'<a href="'+ctx+"/web/jnyz/videoDetail/"+id+'" title="'+title+'">'+title+'</a>'+
										'</h1>'+
										'<p>'+
											'<a href="'+ctx+"/web/jnyz/videoDetail/"+id+'" title="'+title+'">&nbsp; &nbsp; '+brief+'</a>'+
										'</p>'+
									'</div>'+
									'<div class="clear"></div>'+
								'</div>');
					$("#news_data").append(shtml);
				}
				$("#pageSelector").html("");
				for(var i = 0; i < data.totalPage; i++){
					$("#pageSelector").append($("<option selected>第"+(i+1)+"页</option>"));
				}
			}
		});
	}
	
	$("#toLastPage").click(function(){
		if(page > 1){
			loadPage(page-1);
		}
	});
	$("#toNextPage").click(function(){
		if($("#totalPage").val() > page){
			loadPage(page+1);
		}
	});
});